﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CPlatePrintSys.Domain.Events;
using CPlatePrintSys.Infrastructure;
using MahApps.Metro.Controls;
using Prism.Events;
using Prism.Ioc;
using Prism.Navigation.Regions;
using Prism.Unity;

namespace CPlatePrintSys.Win
{
    /// <summary>
    /// Shell.xaml 的交互逻辑
    /// </summary>
    public partial class Shell : MetroWindow
    {
        private IEventAggregator  _eventAggregator;
        public Shell()
        {
            this._eventAggregator = Prism.Ioc.ContainerLocator.Container.Resolve<IEventAggregator>();

            InitializeComponent();

            this.Loaded += Shell_Loaded;    

            this._eventAggregator.GetEvent<WindowsPopupedEvent>().Subscribe(OnWindowsPopuped, ThreadOption.UIThread);
        }

        private void OnWindowsPopuped(bool bShow)
        {
            windowMask.Visibility = bShow ? Visibility.Visible : Visibility.Collapsed;
        }

        private void Shell_Loaded(object sender, RoutedEventArgs e)
        {
            var containerProvider = (App.Current as PrismApplication)?.Container;
            if (containerProvider != null)
            {
                var regionManager = containerProvider.Resolve<IRegionManager>();
                regionManager.RequestNavigate(ConstStrings.UI_Region_Main_Content, "LoginWindowView");
            }
            else
            {
                throw new InvalidOperationException("Container is not initialized.");
            }
        }
    }
}
